<?php
/**
 * Created by PhpStorm.
 * User: jason
 * Date: 2017/12/11
 * Time: 1:49
 */

namespace Home\Service;


use Think\Model;

class ImageService extends Model
{
    /**
     * 保存图片信息
     * @return unknown
     */
    public function saveImg($image){
        //step-1: 查询是否存在
        $Model = D('Image');

        $imageExist = $Model->where(array("url"=>$image['url']))->find();
        if(!empty($imageExist)) {
            return $imageExist['id'];
        }
        //step-2: 设置默认创建者
        $image['creator'] = empty($image['creator']) ? 1 : $image['creator'];

        //step-3: 保存
        return $Model->add($image);

    }
}